﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Dict.DataModel;

namespace Dict.Blo
{
    public class DictCopyMissionBlo 
    {
        public static TableCopyMission GetTableCopyMission(string missionId)
        {
            return Dict.DictDataManager.Instance.tableCopyMissionDao.GetById(missionId);
        }
        
        public static List<TableCopyMission> GetChapterMissionList(string chapterId)
        {
            return Dict.DictDataManager.Instance.tableCopyMissionDao.GetByOneIndex(chapterId);
        }

        public static TableCopyMission GetFirstFallEquipMission(int equipType)
        {
            foreach(var mission in Dict.DictDataManager.Instance.tableCopyMissionDao.CachePrimary)
            {
                string[] dropIds = mission.Value.DropShow.Split(';');
                for (int i = 0; i < dropIds.Length; i++)
                {
                    string[] dropinfo = dropIds[i].Split(',');
                    if (dropinfo[0].StartsWith(Dict.Config.TableConst.equip))
                    {
                        Debug.Log(dropIds[i]);
                        TableEquip equipData = DictEquipBlo.GetTableEquip(dropinfo[0]);
                        if(equipData.type == equipType)
                            return mission.Value;
                    }
                }
            }
            return null;
        }

        //获取掉落某物品的所有mission
        public static List<TableCopyMission> GetFallSthMisstionList(string objId)
        {
            List<TableCopyMission> list = new List<TableCopyMission>();
            foreach (var mission in Dict.DictDataManager.Instance.tableCopyMissionDao.CachePrimary)
            {
                string[] dropIds = mission.Value.DropShow.Split(';');
                for (int i = 0; i < dropIds.Length; i++)
                {
                    string[] dropinfo = dropIds[i].Split(',');
                    if (dropinfo[0].CompareTo(objId) == 0)
                    {
                        list.Add(mission.Value);
                        break;
                    }
                }
            }
            return list;
        }
    }
}

